import os
import subprocess
import sys
import time


def update_entrance() -> None:
    print("[更新]执行 Git 更新...")
    result = subprocess.run(["git", "pull"], capture_output=True, text=True)
    print(f"{result.stdout}")
    if "Already up to date" in result.stdout:
        print("[更新]代码已是最新，无需重启。")
        return
    print("[更新]代码更新完成，获取最新提交内容...")
    log_result = subprocess.run(["git", "log", "-5", "--oneline"], capture_output=True, text=True)
    print(f"{log_result.stdout}")
    print("[更新]准备重启...")
    time.sleep(1)
    python = sys.executable
    os.execl(python, python, *sys.argv)
